import App from './App.vue'
import plugins from './plugins'
import store from './store'
import uviewPlus from 'uview-plus'

import { createSSRApp } from 'vue'
import directive from './directive' // directive

import { useDict } from '@/utils/dict'
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ty'
import { toast } from '@/utils/common'
// import { loader } from "bmap-jsapi-loader"
// 自己的组件
import zmmWatermark from '@/uni_modules/zmm-watermark/components/zmm-watermark/zmm-watermark.vue'
import tyTable from '@/components/ty-table/ty-table'
import tyTableTree from '@/components/ty-table-tree/ty-table-tree'
import tyPagination from '@/components/ty-pagination/ty-pagination.vue'
import tyPicker from '@/components/ty-picker/ty-picker.vue'
import tyDataSelect from '@/components/ty-data-select/ty-data-select.vue'
import tyTree from '@/components/ty-tree/ty-tree'
import pageLayout from '@/components/pageLayout/pageLayout.vue'
import tyDataPicker from '@/components/ty-data-picker/ty-data-picker.vue'
import tyProductPicker from '@/components/ty-product-picker/ty-product-picker.vue'
import tyCustomerPicker from '@/components/ty-customer-picker/ty-customer-picker.vue'
import tySupplierProductPicker from '@/components/ty-supplier-product-picker/ty-supplier-product-picker'
import tyStorageProductPicker from '@/components/ty-storage-product-picker/ty-storage-product-picker'
// uni-ui的组件
import uniIcons from '@dcloudio/uni-ui/lib/uni-icons/uni-icons.vue'
import uniTag from '@dcloudio/uni-ui/lib/uni-tag/uni-tag.vue'
import uniForms from '@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue'
import uniFormsItem from '@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.vue'
import uniEasyinput from '@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.vue'
import uniDatetimePicker from '@dcloudio/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue'
import uniDataSelect from '@dcloudio/uni-ui/lib/uni-data-select/uni-data-select.vue'
import uniDataCheckbox from '@dcloudio/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue'
import uniLoadMore from '@dcloudio/uni-ui/lib/uni-load-more/uni-load-more.vue'
import uniPopup from '@dcloudio/uni-ui/lib/uni-popup/uni-popup.vue'
import uniList from '@dcloudio/uni-ui/lib/uni-list/uni-list.vue'
import uniListItem from '@dcloudio/uni-ui/lib/uni-list-item/uni-list-item.vue'
import uniSwiperDot from '@dcloudio/uni-ui/lib/uni-swiper-dot/uni-swiper-dot.vue'
import uniSection from '@dcloudio/uni-ui/lib/uni-section/uni-section.vue'
import uniPopupDialog from '@dcloudio/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue'
import uniTransition from '@dcloudio/uni-ui/lib/uni-transition/uni-transition.vue'
import uniNumberBox from '@dcloudio/uni-ui/lib/uni-number-box/uni-number-box.vue'

export function createApp() {
  const app = createSSRApp(App)
  app.use(store)
  app.use(uviewPlus)
  app.use(plugins)
	
	app.component('zmm-watermark', zmmWatermark)
	app.component('ty-table', tyTable)
	app.component('ty-table-tree', tyTableTree)
	app.component('ty-pagination', tyPagination)
	app.component('ty-picker', tyPicker)
	app.component('ty-tree', tyTree)
	app.component('pageLayout', pageLayout)
	app.component('ty-data-select', tyDataSelect)
	app.component('ty-data-picker', tyDataPicker)
	app.component('ty-product-picker', tyProductPicker)
	app.component('ty-customer-picker', tyCustomerPicker)
	app.component('ty-supplier-product-picker', tySupplierProductPicker)
	app.component('ty-storage-product-picker', tyStorageProductPicker)
	
	app.component('uni-icons', uniIcons)
	app.component('uni-tag', uniTag)
	app.component('uni-forms', uniForms)
	app.component('uni-forms-item', uniFormsItem)
	app.component('uni-easyinput', uniEasyinput)
	app.component('uni-datetime-picker', uniDatetimePicker)
	app.component('uni-data-select', uniDataSelect)
	app.component('uni-data-checkbox', uniDataCheckbox)
	app.component('uni-load-more', uniLoadMore)
	app.component('uni-popup', uniPopup)
	app.component('uni-list', uniList)
	app.component('uni-list-item', uniListItem)
	app.component('uni-swiper-dot', uniSwiperDot)
	app.component('uni-section', uniSection)
	app.component('uni-popup-dialog', uniPopupDialog)
	app.component('uni-transition', uniTransition)
	app.component('uni-number-box', uniNumberBox)
	

  // #ifndef MP-WEIXIN
  // 微信小程序中不支持自定义指令
  directive(app)
  // #endif

  // 全局方法挂载
	app.config.globalProperties.$store = store
  app.config.globalProperties.toast = toast
  app.config.globalProperties.useDict = useDict
  app.config.globalProperties.parseTime = parseTime
  app.config.globalProperties.resetForm = resetForm
  app.config.globalProperties.handleTree = handleTree
  app.config.globalProperties.addDateRange = addDateRange
  app.config.globalProperties.selectDictLabel = selectDictLabel
  app.config.globalProperties.selectDictLabels = selectDictLabels

  return {
    app
  }
}
